function showAddress(liId){
	var add_li,liArray=new Array();
	liArray["id"]=$("#id").val();
	//liArray["id"]=liId;
	liArray["city_ids"]=$("#city_ids").val();
	liArray["isSelect"]=$("#id").val();
	liArray["receiver"]=$("#receiver").val();
	liArray["chooseCity"]=$(".chooseCity").val();
	liArray["address"]=$("#address").val();
	liArray["phone"]=$("#phone").val();

	 add_li='<li data="'+liId+'" data_cids="'+liArray["city_ids"]+'"><span class="address_id';
	
	 if(liArray["isSelect"]==1){
		add_li+=' address_select address_start';
	 }
	add_li+=' ">';
	 if(liArray["isSelect"]==1){
		add_li+='默认地址';
	 }else{
		 add_li+=liArray["receiver"]+' '+liArray["chooseCity"].substring(0,2);
	 }
	 add_li+='<b></b></span><span class="addrss_name">'+liArray["receiver"]+' '+liArray["chooseCity"].substring(0,2)+'</span>'+liArray["receiver"]+' '+liArray["chooseCity"]+' '+liArray["phone"]+' '+liArray["address"]+'<span class="address_edit"><a href="javascript:void(0);" class="address_default ';
	 
	  if(liArray["isSelect"]==1){
		  add_li+=' address_none';
	  }
	add_li+=' ">设为默认地址</a><a href="javascript:void(0);" class="address_editItem">编辑</a>';
	add_li+='<a href="javascript:void(0);" class="address_del">删除</a></span></li>';
	if(liArray["id"]){
	
		$('#UsersAddress li[data="'+liArray["id"]+'"]').replaceWith(add_li);
	}else{
		$("#UsersAddress").children(":first").before(add_li);
		
		
	}
		
}
$("document").ready(function(){
//初始化	
		var addrs_id=$(".address_start").parent("li").attr("data");
			$("#AddrsId").val(addrs_id);
		var addressLength = parseInt($("#UsersAddress > li").length);
//		alert(addressLength);
		if(addressLength >1){
			$("#UsersAddress>li:gt(0)").hide();
			$(".address_select").show();
			$("#AddressSwitch").show();
			$("#AddressSwitch").removeClass("swith_on");
			$("#AddressSwitch >span").html("更多地址");
		}else{
			$("#AddressSwitch").hide();
		}
	
		
		if($(".address_select")){
			var addrs_id=$(".address_select").parent("li").attr("data")	;		
			$("#AddrsId").val(addrs_id);
		}
		
		//$(".address_select").parent("li").show().siblings().hide();
	
	
//选择地址
	$(document).on('click', '.address_id', function() {
	
		$(this).addClass("address_select");
		$(this).parent("li").siblings().find(".address_id").removeClass("address_select");
		var addrs_id=$(".address_select").parent("li").attr("data");
		$("#AddrsId").val(addrs_id);
	});	

//更多地址
	$(document).on('click', '#AddressSwitch', function() {
		
		if($("#AddressSwitch").hasClass("swith_on")){
			$("#AddressSwitch").removeClass("swith_on");
			$("#AddressSwitch >span").html("更多地址");	
			
			if($("#UsersAddress >li> span").hasClass("address_select")){				
				$(".address_select").parent().show().siblings().hide();	
			}else{
				
				$("#UsersAddress > li:gt(0)").hide();
			}
		}else{
			$("#AddressSwitch").addClass("swith_on");
			$("#AddressSwitch > span").html("收起地址");
			$("#UsersAddress > li").show();
		}
	});	

//默认地址
	$(document).on('click', '.address_default', function() {
		$(this).parents("li").siblings().find(".address_id").removeClass("address_select");
		$(this).addClass("address_none");
		var address_current = $(".address_start");
		if(address_current){
			var address_currentValue=address_current.next().html();
			address_current.removeClass("address_select address_start");
			address_current.siblings().find(".address_default").removeClass("address_none")
			address_current.empty().html(address_currentValue+"<b></b>");
			var oldid= parseInt(address_current.parent("li").attr("data"));
		}
		$(this).parents("li").find(".address_id").addClass("address_select address_start").html("默认地址<b></b>");
		
		var newid= parseInt($(this).parents("li").attr("data"));
		if(newid !=0){
			$.ajax({url:"/Users/usersAddressSel/",data:{id:newid,cid:oldid},success:function(data){
				
				}});
		}
		var addrs_id=$(".address_select").parent("li").attr("data");
		$("#AddrsId").val(addrs_id);
	});	
	
//添加
	
	$(document).on('click', '#UsersAddressAdd', function() {	
	 $.get('/Users/usersAddressAdd',function(data){
		    
        	var index_id =layer.open({type:1,title:'新增收货地址',content:data,end:function(){
		
			$("#UsersAddress > li").find(".address_id").removeClass("address_select");	
			$("#UsersAddress > li:first").find(".address_id").addClass("address_select");
			
			addrs_id=$(".address_select").parent("li").attr("data");
			$("#AddrsId").val(addrs_id);	
			}});
			
        });	

	});	
	

//编辑
	$(document).on('click', '.address_editItem', function() {
	
			var addr_id = $(this).parents("li").attr("data");		
			if(addr_id){
				 $.get('/Users/usersAddressAdd/id/'+addr_id,function(data){
				
					var index_id = layer.open({type:1,title:'编辑收货地址',content:data});
				});			
			}
	});
	
//删除	
	$(document).on('click', '.address_del', function() {	
	
			var addr_li =$(this).parents("li");
			var addr_id = addr_li.attr("data");		
			
			if(addr_id){
				$.ajax({url:"/Users/usersAddressDel/id/"+addr_id,success:function(data){
					//$("#UsersAddressContainer").html(data);
					addr_li.remove();
					var addressLength = parseInt($("#UsersAddress > li").length);
					if(addressLength >3){
						$("#UsersAddress>li:gt(0)").hide();
						$("#AddressSwitch").show();
						$("#AddressSwitch").removeClass("swith_on");
						$("#AddressSwitch >span").html("更多地址");
					}else{
						$("#AddressSwitch").hide();
					}
				}});
			}
	});
//function scrollAddress(){	
//	$("#AddressPanel").slide({titCell:".hd ul",mainCell:".bd ul",autoPage:true,effect:"top",autoPlay:true,vis:3});
//}
});

		

